package com.example.doer.reading;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ab.activity.AbActivity;
import com.ab.view.titlebar.AbTitleBar;

import static com.ab.util.AbToastUtil.showToast;

/**
 * Created by 严旭江 on 2017/7/11.
 */

public class TopicActivity extends AbActivity {
    //添加include下面的四个imageView
    ImageView likeImageView;
    ImageView dislikeImageView;
    ImageView collectImageView;
    ImageView commentImageView;

    private AbTitleBar abTitleBar;
    @Override
    protected void onCreate(Bundle onSavedInstancetype){
        super.onCreate(onSavedInstancetype);
        setAbContentView(R.layout.activity_topic);

        abTitleBar=this.getTitleBar();

        //获取传递的Topic对象
        final Topic receivedTopic = (Topic) getIntent().getSerializableExtra("topicReplyObj");
        ((TextView)findViewById(R.id.nameOfActivityTopic)).setText(receivedTopic.getTopicName());
        ((TextView)findViewById(R.id.userNameOfActivityTopic)).setText(receivedTopic.getUserName());
        ((TextView)findViewById(R.id.contentOfActivityTopic)).setText(receivedTopic.getTopicContent());
        ((ImageView)findViewById(R.id.userResIDOfActivityTopic)).setImageResource(R.drawable.user_icon_test);

        likeImageView = (ImageView)findViewById(R.id.favourImageViewOfActivityTopic);
        likeImageView.setImageResource(R.drawable.icon_like);
        dislikeImageView = (ImageView)findViewById(R.id.dislikeImageViewOfActivityTopic);

        //dislikeImageView.setImageResource(R.drawable.icon_like);
        dislikeImageView.setImageResource(R.drawable.pointing_down);
        collectImageView = (ImageView)findViewById(R.id.collectImageViewOfActivityTopic);
        collectImageView.setImageResource(R.drawable.collection_icon);
        commentImageView = (ImageView)findViewById(R.id.commentImageOfActivityTopic);
        commentImageView.setImageResource(R.drawable.icon_comment);


        //获取评论数目
        ((TextView)findViewById(R.id.commentNumOfBottomTopic)).setText("评论数目 待实现");

        //喜欢
        likeImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                receivedTopic.setFavoCount((receivedTopic.getFavoCount()+1));
                showToast(TopicActivity.this,"赞同观点数量"+receivedTopic.getFavoCount());
                likeImageView.setEnabled(false);
            }
        });
        //不喜欢
        dislikeImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                receivedTopic.setDislikeCount((receivedTopic.getDislikeCount()+1));
                showToast(TopicActivity.this,"反对观点数量"+receivedTopic.getDislikeCount());
                dislikeImageView.setEnabled(false);
            }
        });
        //收藏☆  功能待实现
        collectImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //待实现
                collectImageView.setImageResource(R.drawable.collection_icon_selected);
            }
        });

        //评论ImageView的点击监听
        commentImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Intent intent = new Intent(v.getContext(),TopicActivity.class);
                Intent intent = new Intent(TopicActivity.this,TopicWithReplyActivity.class);
                intent.putExtra("topicObjWithReply",receivedTopic);
                TopicActivity.this.startActivity(intent);
                //v.getContext().startActivity(intent);
                //((Activity)v.getContext()).finish();
            }
        });
    }//end method onCreate
}//end class
